home *** CD-ROM | disk | FTP | other *** search
/ Take-Home Tutor en Espanol / TakeHomeTutor.iso / pc / En espanol / Take-Home Tutor 3 / template5.swf / scripts / frame_1 / DoAction.as
Encoding:
Text File  |  2003-10-07  |  47.4 KB  |  1,773 lines

  1. function ext_XML_GET_TEXT()
  2. {
  3.    return this.firstChild.nodeType != 3 ? null : this.firstChild.nodeValue;
  4. }
  5. function ext_XML_SET_TEXT(text)
  6. {
  7.    this.firstChild.nodeValue = text;
  8. }
  9. function ActivityInfoItem()
  10. {
  11. }
  12. function ActivityInfo()
  13. {
  14. }
  15. function createIndexList(str, openTag, closeTag)
  16. {
  17.    var len = str.length;
  18.    var acntr = 0;
  19.    var otag = openTag;
  20.    var ctag = closeTag;
  21.    var abi = [];
  22.    var aei = [];
  23.    while(acntr < len)
  24.    {
  25.       acntr = str.indexOf(otag,acntr);
  26.       if(acntr == -1)
  27.       {
  28.          break;
  29.       }
  30.       abi.push(acntr);
  31.       acntr += otag.length;
  32.    }
  33.    acntr = 0;
  34.    while(acntr < len)
  35.    {
  36.       acntr = str.indexOf(ctag,acntr);
  37.       if(acntr == -1)
  38.       {
  39.          break;
  40.       }
  41.       aei.push(acntr);
  42.       acntr += ctag.length;
  43.    }
  44.    var rf = otag.length + ctag.length;
  45.    var i = 0;
  46.    while(i < abi.length)
  47.    {
  48.       if(i == 0)
  49.       {
  50.          aei[i] -= ctag.length - 1;
  51.       }
  52.       else
  53.       {
  54.          abi[i] -= rf * i;
  55.          aei[i] -= rf * i + otag.length;
  56.       }
  57.       i++;
  58.    }
  59.    return {startIndex:abi,endIndex:aei,length:abi.length};
  60. }
  61. function createInstructionField(cnt, name, text)
  62. {
  63.    text = simpleReplaceBlanks(text,"[:blank:]","[:/blank:]");
  64.    var hasBold = text.indexOf("[:bold:]") != -1;
  65.    if(cnt[name] == null)
  66.    {
  67.       var tmc = cnt.createEmptyMovieClip(name,1667);
  68.       tmc.createTextField("content",1,0,0,0,0);
  69.    }
  70.    else
  71.    {
  72.       var tmc = cnt[name];
  73.       tmc.swapDepths(1667);
  74.    }
  75.    tmc.isRemoveable = true;
  76.    tmc.isRemovable = true;
  77.    var tf = layoutInfo.instTextFormat;
  78.    tmc.content.border = false;
  79.    tmc.content.type = "dynamic";
  80.    if(hasBold)
  81.    {
  82.       tmc.content.text = text.replace("[:bold:]","").replace("[:/bold:]","");
  83.    }
  84.    else
  85.    {
  86.       tmc.content.text = text;
  87.    }
  88.    tmc.content._height = 400;
  89.    tmc.content.wordWrap = true;
  90.    tmc.content.color = layoutInfo.instTextColor;
  91.    tmc.content._width = 300;
  92.    tmc.content.autoSize = true;
  93.    tmc.content.selectable = false;
  94.    tmc.content.setTextFormat(tf);
  95.    tmc.content.embedFonts = true;
  96.    if(hasBold)
  97.    {
  98.       var idxLists = createIndexList(text,"[:bold:]","[:/bold:]");
  99.       var i = 0;
  100.       while(i < idxLists.length)
  101.       {
  102.          tmc.content.setTextFormat(idxLists.startIndex[i],idxLists.endIndex[i],layoutInfo.instTextFormatBold);
  103.          i++;
  104.       }
  105.    }
  106.    return tmc;
  107. }
  108. function changeInstructionField(insField, newText)
  109. {
  110.    createInstructionField(insField._parent,insField._name,newText);
  111. }
  112. function toggleLang()
  113. {
  114.    if(PMSI.instructionLanguage == "Spanish")
  115.    {
  116.       PMSI.instructionLanguage = "English";
  117.    }
  118.    else
  119.    {
  120.       PMSI.instructionLanguage = "Spanish";
  121.    }
  122.    var instText = ai["instructions" + PMSI.instructionLanguage].text;
  123.    if(instText != null)
  124.    {
  125.       var oldInstHeight = this.instructionField._height;
  126.       changeInstructionField(this.instructionField,instText);
  127.       var hdiff = this.instructionField._height - oldInstHeight;
  128.       reposition(hdiff);
  129.    }
  130.    pencilHelper.swapLangs();
  131. }
  132. function reposition(hdiff)
  133. {
  134.    var comp;
  135.    var dupList = {};
  136.    trace("******************************************");
  137.    for(var mcn in this)
  138.    {
  139.       comp = this[mcn];
  140.       if(comp.isMoveable && dupList[comp._name] == null)
  141.       {
  142.          trace("\t" + comp);
  143.          trace("\t\t" + comp.getDepth());
  144.          trace(hdiff);
  145.          comp._y += hdiff;
  146.          dupList[comp._name] = 1;
  147.       }
  148.    }
  149.    trace("******************************************");
  150. }
  151. function simpleReplaceBlanks(str, stag, etag)
  152. {
  153.    var cp = str.indexOf(stag);
  154.    var ei = 0;
  155.    while(cp != -1)
  156.    {
  157.       ei = str.indexOf(etag);
  158.       str = str.substring(0,cp) + "_____" + str.substring(ei + etag.length);
  159.       cp = str.indexOf(stag);
  160.    }
  161.    return str;
  162. }
  163. function loadActivity(fname)
  164. {
  165.    t = getTimer();
  166.    ai.load(fname);
  167. }
  168. function setActivityInfo(_ai)
  169. {
  170.    ai = _ai;
  171.    render();
  172.    return true;
  173. }
  174. function render()
  175. {
  176.    tabOrder = 4000;
  177.    depth = 3000;
  178.    delete this.answerList;
  179.    this.answerList = new Array();
  180.    if(parseInt(ai.type.text) == master.activityTypes.MULTI)
  181.    {
  182.       this.isMulti = true;
  183.    }
  184.    clearClip();
  185.    var tableY = layoutInfo.box.y;
  186.    var rightSideBuffer = layoutInfo.rightSideBuffer;
  187.    var topBuffer = 0;
  188.    if(master.hasVideoPlayer)
  189.    {
  190.       tableY = layoutInfo.temp4InstY;
  191.       topBuffer = master.videoPlayer._height;
  192.       rightSideBuffer = 250;
  193.    }
  194.    else if(master.hasMediaFrame)
  195.    {
  196.       rightSideBuffer = 250;
  197.    }
  198.    trace(this + ".render: called");
  199.    var title_mc;
  200.    var inst_mc;
  201.    if(ai.titleSpanish)
  202.    {
  203.       title_mc = createTitleField(ai.titleSpanish);
  204.       title_mc._x = layoutInfo.box.x;
  205.       title_mc._y = layoutInfo.box.y + topBuffer;
  206.       tableY = title_mc._y + title_mc._height;
  207.    }
  208.    if(ai.instructionsEnglish == null && ai.instructionsSpanish == null && !(ai.questions instanceof Array))
  209.    {
  210.       ai.activity.instructionsEnglish = {text:ai.questions.question.questionText.text};
  211.       ai.activity.instructionsSpanish = {text:ai.questions.question.questionTextSpanish.text};
  212.       delete ai.activity.questions.question.questionText;
  213.       delete ai.activity.questions.question.questionTextSpanish;
  214.    }
  215.    if(ai.instructionsEnglish || ai.instructionsSpanish)
  216.    {
  217.       if(ai.instructionsEnglish != null)
  218.       {
  219.          var instText = ai.instructionsEnglish.text;
  220.       }
  221.       else
  222.       {
  223.          var instText = ai.instructionsSpanish.text;
  224.       }
  225.       pinstText = ai["instructions" + PMSI.instructionLanguage].text;
  226.       instText = pinstText != null ? pinstText : instText;
  227.       inst_mc = createInstructionField(this,"inst",instText);
  228.       inst_mc._x = layoutInfo.box.x;
  229.       inst_mc._y = title_mc == null ? tableY : title_mc._y + title_mc._height;
  230.       trace("INST Y: " + inst_mc._y);
  231.       tableY = inst_mc._y + inst_mc._height;
  232.       this.instructionField = inst_mc;
  233.       trace("tableY (first check): " + tableY);
  234.       trace("INSTRUCTIONS?!?: " + inst_mc);
  235.       hasInstructions = true;
  236.    }
  237.    else
  238.    {
  239.       hasInstructions = false;
  240.    }
  241.    if(ai.reference != null)
  242.    {
  243.       this._parent.showRefWinButton(layoutInfo.box.x,tableY);
  244.       tableY += 15;
  245.    }
  246.    if(ai.videoFile == null && _parent.actNumber_mc._height > inst_mc._height + title_mc._height && hasInstructions)
  247.    {
  248.       tableY = _parent.actNumber_mc._y + _parent.actNumber_mc._height + 10;
  249.    }
  250.    tableY = tableY != 0 ? tableY : layoutInfo.box.y;
  251.    trace("tableY: " + (tableY + topBuffer));
  252.    trace("rightSideBuffer: " + rightSideBuffer);
  253.    table = new TableClass(this);
  254.    tables = new Array();
  255.    atables = new Array();
  256.    var isMultiQuestion = ai.questions.question instanceof Array;
  257.    if(!(ai.questions.question instanceof Array))
  258.    {
  259.       var tempa = new Array();
  260.       tempa.push(ai.questions.question);
  261.       ai.questions.question = tempa;
  262.    }
  263.    var qlen = ai.questions.question.length;
  264.    var qtc;
  265.    var qtr;
  266.    var answerChoices;
  267.    var answerText;
  268.    var question;
  269.    var answer;
  270.    var checkbox;
  271.    var feedbackCheck;
  272.    var mcon;
  273.    var i = 0;
  274.    while(i < qlen)
  275.    {
  276.       mcon = this.createEmptyMovieClip("qcon" + i,5000 + i);
  277.       mcon.isMoveable = true;
  278.       if(isMultiQuestion)
  279.       {
  280.          var questionText;
  281.          var answerText1;
  282.          var answerText2;
  283.          questionText = ai.questions.question[i].questionText.text;
  284.          if(questionText != null)
  285.          {
  286.             question = createQuestionField(mcon,i,replaceBlanks(questionText,8));
  287.          }
  288.       }
  289.       tables[i] = new TableClass();
  290.       qtc = new TableCell(question);
  291.       qtr = new TableRow();
  292.       qtr.addCell(qtc);
  293.       tables[i].addRow(qtr);
  294.       atables[i] = new TableClass();
  295.       answerChoices = ai.questions.question[i].answerChoice;
  296.       var j = 0;
  297.       while(j < answerChoices.length)
  298.       {
  299.          answerText = answerChoices[j];
  300.          feedbackCheck = mcon.attachMovie("check","correctcheck_" + i + "_" + j,depth++);
  301.          feedbackCheck.isMoveable = true;
  302.          checkbox = mcon.attachMovie("radiobutton","check_" + i + "_" + j,depth++);
  303.          checkbox.isMoveable = true;
  304.          checkbox.tabIndex = tabOrder++;
  305.          answerList.push(checkbox);
  306.          checkbox.feedbackCheck = feedbackCheck;
  307.          checkbox.onRelease = answerOnRelease;
  308.          checkbox.groupId = i;
  309.          if(answerText.text == ai.questions.question[i].correctAnswer.text)
  310.          {
  311.             checkbox.isCorrectAnswer = true;
  312.          }
  313.          else
  314.          {
  315.             checkbox.isCorrectAnswer = false;
  316.          }
  317.          answer = createAnswerField(mcon,j,0,answerText);
  318.          answer.isMoveable = true;
  319.          qtr = new TableRow();
  320.          qtc = new TableCell(feedbackCheck);
  321.          qtr.addCell(qtc);
  322.          qtc = new TableCell(checkbox);
  323.          qtr.addCell(qtc);
  324.          qtc = new TableCell(answer);
  325.          qtr.addCell(qtc);
  326.          atables[i].addRow(qtr);
  327.          j++;
  328.       }
  329.       i++;
  330.    }
  331.    trace("tableY: " + tableY);
  332.    var tableWidth = layoutinfo.MAX_WIDTH - rightSideBuffer;
  333.    trace("layoutinfo.MAX_WIDTH: " + layoutinfo.MAX_WIDTH);
  334.    trace("rightSideBuffer " + rightSideBuffer);
  335.    trace("TABLE WIDTH: " + tableWidth);
  336.    var ttab;
  337.    var atab;
  338.    var tableY1 = tableY;
  339.    var tableY2 = tableY;
  340.    var maxHeight = 0;
  341.    var divsor = atables.length <= 3 ? 1 : 2;
  342.    var i = 0;
  343.    while(i < tables.length)
  344.    {
  345.       trace("i: " + i);
  346.       ttab = tables[i];
  347.       ttab.setPosition({x:0,y:0});
  348.       ttab.setCellSpacing(6);
  349.       ttab.init();
  350.       ttab.setWidth(tableWidth / divsor);
  351.       trace(ttab.height);
  352.       tableY1 += ttab.height;
  353.       trace("ASDA: " + ttab.width);
  354.       atab = atables[i];
  355.       atab.setPosition({x:0,y:ttab.height + 4});
  356.       atab.setCellSpacing(6);
  357.       atab.init();
  358.       atab.setWidth(tableWidth / divsor);
  359.       trace(atab.height);
  360.       tableY1 += atab.height - 30;
  361.       if(maxHeight < ttab.height + atab.height)
  362.       {
  363.          maxHeight = ttab.height + atab.height;
  364.       }
  365.       trace("maxHeight: " + maxHeight);
  366.       i++;
  367.    }
  368.    biglayout = new TableClass();
  369.    qtr = new TableRow();
  370.    qtc = new TableCell(qcon0);
  371.    qtr.addCell(qtc);
  372.    qtc = new TableCell(qcon1);
  373.    qtr.addCell(qtc);
  374.    biglayout.addRow(qtr);
  375.    qtr = new TableRow();
  376.    qtc = new TableCell(qcon2);
  377.    qtr.addCell(qtc);
  378.    qtc = new TableCell(qcon3);
  379.    qtr.addCell(qtc);
  380.    biglayout.addRow(qtr);
  381.    qtr = new TableRow();
  382.    qtc = new TableCell(qcon4);
  383.    qtr.addCell(qtc);
  384.    qtc = new TableCell(qcon5);
  385.    qtr.addCell(qtc);
  386.    biglayout.addRow(qtr);
  387.    biglayout.setPosition({x:layoutInfo.box.x,y:tableY});
  388.    biglayout.setCellSpacing(20);
  389.    biglayout.init();
  390. }
  391. function answerOnRollOver()
  392. {
  393.    this.gotoAndStop("rollOver");
  394. }
  395. function answerOnRollOut()
  396. {
  397.    this.gotoAndStop("rollOut");
  398. }
  399. function answerOnRelease()
  400. {
  401.    if(this._parent._parent.isMulti)
  402.    {
  403.       var groupId = this.groupId;
  404.       var gmem;
  405.       var i = 0;
  406.       while(true)
  407.       {
  408.          gmem = this._parent["check_" + groupId + "_" + i];
  409.          if(gmem == null)
  410.          {
  411.             break;
  412.          }
  413.          trace(gmem);
  414.          if(gmem != this)
  415.          {
  416.             gmem.gotoAndStop("notSelected");
  417.             gmem.isSelected = false;
  418.          }
  419.          i++;
  420.       }
  421.    }
  422.    trace(this + ": " + this.isSelected);
  423.    if(!this.isSelected || this.isSelected == null)
  424.    {
  425.       this.isSelected = true;
  426.       this.gotoAndStop("selected");
  427.    }
  428.    else
  429.    {
  430.       this.isSelected = false;
  431.       this.gotoAndStop("notSelected");
  432.    }
  433. }
  434. function createQuestionField(cnt, id, text)
  435. {
  436.    var mc = cnt.createEmptyMovieClip("question" + id,depth++);
  437.    mc.createTextField("content",1,0,0,0,0);
  438.    var tf = layoutInfo.qTextFormatMULTI;
  439.    mc.content.embedFonts = true;
  440.    mc.content.border = TXT_DEBUG_SHOW_BORDERS;
  441.    mc.content.type = "dynamic";
  442.    mc.content.text = text;
  443.    mc.content.autoSize = true;
  444.    mc.content.setTextFormat(tf);
  445.    mc.content.selectable = false;
  446.    return mc;
  447. }
  448. function createAnswerField(cnt, id, subid, text)
  449. {
  450.    var amc1 = cnt.createEmptyMovieClip("answer" + subid + "_" + id,depth++);
  451.    amc1.createTextField("content",1,0,0,0,0);
  452.    var tf2 = layoutInfo.answerTextFormat1;
  453.    amc1.content.embedFonts = true;
  454.    amc1.content.border = TXT_DEBUG_SHOW_BORDERS;
  455.    amc1.content.type = "dynamic";
  456.    amc1.content.text = text;
  457.    amc1.content.autoSize = true;
  458.    amc1.content.selectable = false;
  459.    amc1.content.setTextFormat(tf2);
  460.    return amc1;
  461. }
  462. function createAnswerSpacer(cnt, id)
  463. {
  464.    var amcSpacer = cnt.createEmptyMovieClip("answerSpacer_" + id,depth++);
  465.    amcSpacer.createTextField("content",1,0,0,0,0);
  466.    var tf2 = layoutInfo.answerTextFormat1;
  467.    amcSpacer.content.embedFonts = true;
  468.    amcSpacer.content.border = TXT_DEBUG_SHOW_BORDERS;
  469.    amcSpacer.content.type = "dynamic";
  470.    amcSpacer.content.text = "  ";
  471.    amcSpacer.content.autoSize = true;
  472.    amcSpacer.content.setTextFormat(tf2);
  473.    amcSpacer.content.selectable = false;
  474.    return amcSpacer;
  475. }
  476. function checkAnswers()
  477. {
  478.    var qlen = ai.questions.question.length;
  479.    var correct = 0;
  480.    var clp;
  481.    var i = 0;
  482.    while(i < answerList.length)
  483.    {
  484.       clp = answerList[i];
  485.       if(clp.isSelected && clp.isCorrectAnswer)
  486.       {
  487.          correct++;
  488.          clp.feedbackCheck.gotoAndStop("correct");
  489.       }
  490.       else if(clp.isSelected && !clp.isCorrectAnswer)
  491.       {
  492.          clp.feedbackCheck.gotoAndStop("incorrect");
  493.       }
  494.       else
  495.       {
  496.          clp.feedbackCheck.gotoAndStop(1);
  497.       }
  498.       i++;
  499.    }
  500.    master.setFeedback(correct,qlen);
  501. }
  502. function createTitleField(txt)
  503. {
  504.    var mc = this.createEmptyMovieClip("title",depth++);
  505.    mc.createTextField("content",1,0,0,0,0);
  506.    var tf = layoutInfo.titleTextFormat;
  507.    mc.content.embedFonts = true;
  508.    mc.content.border = false;
  509.    mc.content.type = "dynamic";
  510.    mc.content.text = txt;
  511.    mc.content.setTextFormat(tf);
  512.    mc.content.wordWrap = true;
  513.    mc.content.color = layoutInfo.instTextColor;
  514.    mc.content._width = 300;
  515.    mc.content.autoSize = true;
  516.    mc.content.selectable = false;
  517.    return mc;
  518. }
  519. function highlightIncorrect(text)
  520. {
  521. }
  522. function clearClip()
  523. {
  524.    layoutInfo.qMaxWidthPos = 0;
  525.    layoutInfo.qMaxWidth = 0;
  526.    layoutInfo.a1MaxWidth = 0;
  527.    layoutInfo.a2MaxWidth = 0;
  528.    for(var mc in this)
  529.    {
  530.       if(this[mc] != _parent && this[mc] != this)
  531.       {
  532.          this[mc].clear();
  533.          this[mc].removeMovieClip();
  534.       }
  535.    }
  536. }
  537. function drawDebugBox()
  538. {
  539.    this.lineStyle(1,16711680,100);
  540.    this.drawRect(layoutInfo.box.x,layoutInfo.box.y,layoutInfo.MAX_WIDTH,layoutInfo.MAX_HEIGHT);
  541. }
  542. function replaceBlanks(s_str, maxlen)
  543. {
  544.    trace("MAXLEN: " + maxlen);
  545.    var str = s_str.toString();
  546.    return replaceBlanksR(str,maxlen);
  547. }
  548. function replaceBlanksR(s_str, maxlen)
  549. {
  550.    trace(s_str);
  551.    var si = s_str.indexOf(TAGS.BLANK_OPEN);
  552.    if(si == -1)
  553.    {
  554.       return s_str;
  555.    }
  556.    var ei = s_str.indexOf(TAGS.BLANK_CLOSE) + TAGS.BLANK_CLOSE.length;
  557.    s_str = s_str.slice(0,si) + makeStringFromChar("_",maxlen) + s_str.slice(ei,s_str.length);
  558.    return replaceBlanks(s_str,maxlen);
  559. }
  560. function makeStringFromChar(char, length)
  561. {
  562.    var str = "";
  563.    var i = 0;
  564.    while(i < length)
  565.    {
  566.       str += char;
  567.       i++;
  568.    }
  569.    return str;
  570. }
  571. if(_global.PMSI == null)
  572. {
  573.    _global.PMSI = {};
  574.    PMSI.VENDOR_NAME = "Purple Monkey Studios, Inc.";
  575.    PMSI.DefList = {};
  576. }
  577. String.prototype.trim = function()
  578. {
  579.    return this.rtrim().ltrim();
  580. };
  581. String.prototype.rtrim = function()
  582. {
  583.    var i = this.length - 1;
  584.    while(i >= 0 && this.charCodeAt(i) <= 32)
  585.    {
  586.       i--;
  587.    }
  588.    return this.substring(0,i + 1);
  589. };
  590. String.prototype.ltrim = function()
  591. {
  592.    var i = 0;
  593.    while(i < this.length && this.charCodeAt(i) <= 32)
  594.    {
  595.       i++;
  596.    }
  597.    return this.substring(i);
  598. };
  599. String.prototype.isWhiteSpace = function()
  600. {
  601.    var i = 0;
  602.    while(i < this.length)
  603.    {
  604.       if(this.charCodeAt(i) > 32)
  605.       {
  606.          return false;
  607.       }
  608.       i++;
  609.    }
  610.    return true;
  611. };
  612. String.prototype.toCharArray = function()
  613. {
  614.    return this.split("");
  615. };
  616. Array.prototype.charArrayToString = function()
  617. {
  618.    return this.join("");
  619. };
  620. String.prototype.reverse = function()
  621. {
  622.    return this.split("").reverse().join("");
  623. };
  624. String.prototype.multiSplit = function()
  625. {
  626.    var master;
  627.    var dummy;
  628.    var args;
  629.    master = this.split(arguments[0]);
  630.    var i = 1;
  631.    while(i < arguments.length)
  632.    {
  633.       var j = 0;
  634.       while(j < master.length)
  635.       {
  636.          dummy = master[j].split(arguments[i]);
  637.          if(dummy.length > 1)
  638.          {
  639.             args = [j,1];
  640.             args = args.concat(dummy);
  641.             master.splice.apply(master,args);
  642.          }
  643.          j++;
  644.       }
  645.       i++;
  646.    }
  647.    return master;
  648. };
  649. String.prototype.replace = function(srch, repl)
  650. {
  651.    return this.split(srch).join(repl);
  652. };
  653. XML.prototype.ELEMENT_NODE = 1;
  654. XML.prototype.TEXT_NODE = 3;
  655. XML.prototype._inorderItr = function(node, fnPtr)
  656. {
  657.    var stack = new Array();
  658.    var node = node;
  659.    while(true)
  660.    {
  661.       if(node)
  662.       {
  663.          stack.push(node);
  664.          node = node.firstChild;
  665.       }
  666.       else
  667.       {
  668.          node = stack.pop();
  669.          if(!node)
  670.          {
  671.             break;
  672.          }
  673.          fnPtr(node);
  674.          node = node.nextSibling;
  675.       }
  676.    }
  677.    delete stack;
  678. };
  679. XMLNode.prototype._inorderItr = XML.prototype._inorderItr;
  680. XML.prototype._inorderRec = function(node, fnPtr)
  681. {
  682.    function helperR(node_xml)
  683.    {
  684.       if(node_xml == null)
  685.       {
  686.          return undefined;
  687.       }
  688.       this.fnPtr(node_xml);
  689.       helperR(node_xml.firstChild);
  690.       helperR(node_xml.nextSibling);
  691.    }
  692.    var outer = this;
  693.    helperR(node);
  694. };
  695. XMLNode.prototype._inorderRec = XML.prototype._inorderRec;
  696. XMLNode.prototype.addProperty("text",this.ext_XML_GET_TEXT,this.ext_XML_SET_TEXT);
  697. XML.prototype.addProperty("text",this.ext_XML_GET_TEXT,this.ext_XML_SET_TEXT);
  698. XML.prototype.getElementsByTagName = function(tagName)
  699. {
  700.    function processNode(node)
  701.    {
  702.       if(node.nodeName != null && node.nodeName == tagName)
  703.       {
  704.          nodelist.push(node);
  705.       }
  706.    }
  707.    var nodelist = new Array();
  708.    this._inorderItr(this,processNode);
  709.    return nodelist;
  710. };
  711. XMLNode.prototype.getElementsByTagName = XML.prototype.getElementsByTagName;
  712. XML.prototype.getElementsByTagNames = function()
  713. {
  714.    function processNode(node)
  715.    {
  716.       var i = 0;
  717.       while(i < args.length)
  718.       {
  719.          if(node.nodeName != null && node.nodeName == args[i])
  720.          {
  721.             trace("Found: " + args[i]);
  722.             if(nodelists[i] == undefined)
  723.             {
  724.                nodelists[i] = new Array();
  725.             }
  726.             nodelists[i].push(node);
  727.             break;
  728.          }
  729.          i++;
  730.       }
  731.    }
  732.    var args = arguments;
  733.    var nodelists = new Array(arguments.length);
  734.    this._inorderItr(this,processNode);
  735.    return nodelists;
  736. };
  737. XMLNode.prototype.getElementsByTagNames = XML.prototype.getElementsByTagNames;
  738. XML.prototype.getValueAtTagName = function(tagName)
  739. {
  740.    function processNode(node)
  741.    {
  742.       if(node.nodeName != null && node.nodeName == tagName)
  743.       {
  744.          nodelist.push(node);
  745.       }
  746.    }
  747.    var nodelist = new Array();
  748.    var textValue = null;
  749.    this._inorderItr(this,processNode);
  750.    if(nodeList.length >= 1)
  751.    {
  752.       textValue = nodeList[0].text;
  753.    }
  754.    return textValue;
  755. };
  756. XMLNode.prototype.getValueAtTagName = XML.prototype.getValueAtTagName;
  757. XML.prototype.getAttribute = function(name)
  758. {
  759.    return this.attributes[name];
  760. };
  761. XMLNode.prototype.getAttribute = XML.prototype.getAttribute;
  762. XML.prototype.setAttribute = function(name, value)
  763. {
  764.    this.attributes[name] = value;
  765. };
  766. XMLNode.prototype.setAttribute = XML.prototype.setAttribute;
  767. XML.prototype.hasAttribute = function(name)
  768. {
  769.    var attrs = this.attributes;
  770.    for(var mc in attrs)
  771.    {
  772.       if(name == mc)
  773.       {
  774.          return true;
  775.       }
  776.    }
  777.    return false;
  778. };
  779. XMLNode.prototype.hasAttribute = XML.prototype.hasAttribute;
  780. XML.prototype.removeAttribute = function(name)
  781. {
  782.    var attr = this.attributes[name];
  783.    delete this.attributes[name];
  784.    return attr;
  785. };
  786. XMLNode.prototype.setAttribute = XML.prototype.setAttribute;
  787. XMLNode.prototype.getOwnerDocument = function()
  788. {
  789.    var odc = this;
  790.    var lastNode = this;
  791.    while(odc)
  792.    {
  793.       lastNode = odc;
  794.       odc = odc.parentNode;
  795.    }
  796.    return !(lastNode instanceof XML) ? null : lastNode;
  797. };
  798. XML.prototype.normalize = function()
  799. {
  800.    function process(node)
  801.    {
  802.       nodeList.push(node);
  803.    }
  804.    var outer = this;
  805.    var nodeList = new Array();
  806.    this._inorderItr(this,process);
  807.    var i = 0;
  808.    while(i < nodeList.length)
  809.    {
  810.       var node = nodeList[i];
  811.       if(node.nodeType == XML.prototype.TEXT_NODE && node.nodeValue.isWhiteSpace())
  812.       {
  813.          trace("removing node");
  814.          node.removeNode();
  815.       }
  816.       else if(node.nodeType == XML.prototype.TEXT_NODE)
  817.       {
  818.          node.nodeValue = node.nodeValue.trim();
  819.       }
  820.       i++;
  821.    }
  822.    delete nodeList;
  823. };
  824. XMLNode.prototype.normalize = XML.prototype.normalize;
  825. XMLNode.prototype.getDepth = function()
  826. {
  827.    var i = 0;
  828.    var node = this;
  829.    while(node)
  830.    {
  831.       node = node.parentNode;
  832.       i++;
  833.    }
  834.    return i;
  835. };
  836. XML.prototype.getElementsWithAttribute = function(name, value)
  837. {
  838.    function processNode(node)
  839.    {
  840.       if(value == null)
  841.       {
  842.          for(var mcz in node.attributes)
  843.          {
  844.             if(mcz == name)
  845.             {
  846.                nodeList.push(node);
  847.                break;
  848.             }
  849.          }
  850.       }
  851.       else if(node.attributes[name] == value)
  852.       {
  853.          nodeList.push(node);
  854.       }
  855.    }
  856.    if(name == null)
  857.    {
  858.       return undefined;
  859.    }
  860.    var nodeList = new Array();
  861.    this._inorderItr(this,processNode);
  862.    return nodeList;
  863. };
  864. XMLNode.prototype.getElementsWithAttribute = XML.prototype.getElementsWithAttribute;
  865. XMLNode.prototype.getPath = function(path)
  866. {
  867.    function process(node)
  868.    {
  869.       trace(node.nodeName);
  870.       if(node.nodeName != null && node.nodeName == currentPart && i < pathParts.length)
  871.       {
  872.          trace("Found: " + currentPart);
  873.          partTable[i] = node.parentNode.getElementsByTagName(currentPart);
  874.          currentPart = pathParts[++i];
  875.       }
  876.    }
  877.    var i = 0;
  878.    var pathParts = path.split("/");
  879.    var currentPart = pathParts[i];
  880.    var partTable = new Array();
  881.    this._inorderItr(this,process);
  882.    return partTable[partTable.length - 1];
  883. };
  884. XML.prototype.getPath = XMLNode.prototype.getPath;
  885. MovieClip.prototype.isLoading = function()
  886. {
  887.    return this.getBytesLoaded() > 4 && this.getBytesTotal() > this.getBytesLoaded();
  888. };
  889. MovieClip.prototype.getPercentLoaded = function()
  890. {
  891.    return Math.round(this.getBytesLoaded() / this.getBytesTotal() * 100);
  892. };
  893. MovieClip.prototype.isLoaded = function()
  894. {
  895.    return !this.isLoading();
  896. };
  897. MovieClip.prototype._sol = function(f)
  898. {
  899.    if(MovieClip.prototype.__onLoadHandler__ == undefined)
  900.    {
  901.       MovieClip.prototype.__onLoadHandler__ = {};
  902.    }
  903.    MovieClip.prototype.__onLoadHandler__[this] = f;
  904. };
  905. MovieClip.prototype._gol = function()
  906. {
  907.    return MovieClip.prototype.__onLoadHandler__[this];
  908. };
  909. MovieClip.prototype.addProperty("onLoad",MovieClip.prototype._gol,MovieClip.prototype._sol);
  910. MovieClip.prototype._sod = function(f)
  911. {
  912.    if(MovieClip.prototype.__onDataHandler__ == undefined)
  913.    {
  914.       MovieClip.prototype.__onDataHandler__ = {};
  915.    }
  916.    MovieClip.prototype.__onDataHandler__[this] = f;
  917. };
  918. MovieClip.prototype._god = function()
  919. {
  920.    return MovieClip.prototype.__onDataHandler__[this];
  921. };
  922. MovieClip.prototype.addProperty("onData",MovieClip.prototype._god,MovieClip.prototype._sod);
  923. MovieClip.prototype.load = MovieClip.prototype.loadMovie;
  924. MovieClip.prototype.drawOval = function(x, y, radius, yRadius)
  925. {
  926.    if(arguments.length < 3)
  927.    {
  928.       return undefined;
  929.    }
  930.    var theta;
  931.    var xrCtrl;
  932.    var yrCtrl;
  933.    var angle;
  934.    var angleMid;
  935.    var px;
  936.    var py;
  937.    var cx;
  938.    var cy;
  939.    if(yRadius == undefined)
  940.    {
  941.       yRadius = radius;
  942.    }
  943.    theta = 0.7853981633974483;
  944.    xrCtrl = radius / Math.cos(theta / 2);
  945.    yrCtrl = yRadius / Math.cos(theta / 2);
  946.    angle = 0;
  947.    this.moveTo(x + radius,y);
  948.    var i = 0;
  949.    while(i < 8)
  950.    {
  951.       angle += theta;
  952.       angleMid = angle - theta / 2;
  953.       cx = x + Math.cos(angleMid) * xrCtrl;
  954.       cy = y + Math.sin(angleMid) * yrCtrl;
  955.       px = x + Math.cos(angle) * radius;
  956.       py = y + Math.sin(angle) * yRadius;
  957.       this.curveTo(cx,cy,px,py);
  958.       i++;
  959.    }
  960. };
  961. MovieClip.prototype.drawCircle = function(x, y, r)
  962. {
  963.    this.drawOval(x,y,r);
  964. };
  965. MovieClip.prototype.drawSquare = function(x, y, w)
  966. {
  967.    this.drawRect(x,y,w,w);
  968. };
  969. MovieClip.prototype.drawEgg = function(x, y, r)
  970. {
  971.    var rx = r / 1.618;
  972.    var ry = r;
  973.    var ry1 = 2 * ry * 0.618;
  974.    var ry2 = 2 * ry * 0.382;
  975.    this.moveTo(x + rx,y);
  976.    this.curveTo(rx + x,-0.4142 * ry1 + y,0.7071 * rx + x,-0.7071 * ry1 + y);
  977.    this.curveTo(0.4142 * rx + x,- ry1 + y,x,- ry1 + y);
  978.    this.curveTo(-0.4142 * rx + x,- ry1 + y,-0.7071 * rx + x,-0.7071 * ry1 + y);
  979.    this.curveTo(- rx + x,-0.4142 * ry1 + y,- rx + x,y);
  980.    this.curveTo(- rx + x,0.4142 * ry2 + y,-0.7071 * rx + x,0.7071 * ry2 + y);
  981.    this.curveTo(-0.4142 * rx + x,ry2 + y,x,ry2 + y);
  982.    this.curveTo(0.4142 * rx + x,ry2 + y,0.7071 * rx + x,0.7071 * ry2 + y);
  983.    this.curveTo(rx + x,0.4142 * ry2 + y,rx + x,y);
  984. };
  985. MovieClip.prototype.drawRect = function(x, y, w, h, cornerRadius)
  986. {
  987.    if(arguments.length < 4)
  988.    {
  989.       return undefined;
  990.    }
  991.    if(cornerRadius > 0)
  992.    {
  993.       var theta;
  994.       var angle;
  995.       var cx;
  996.       var cy;
  997.       var px;
  998.       var py;
  999.       if(cornerRadius > Math.min(w,h) / 2)
  1000.       {
  1001.          cornerRadius = Math.min(w,h) / 2;
  1002.       }
  1003.       theta = 0.7853981633974483;
  1004.       this.moveTo(x + cornerRadius,y);
  1005.       this.lineTo(x + w - cornerRadius,y);
  1006.       angle = -1.5707963267948966;
  1007.       cx = x + w - cornerRadius + Math.cos(angle + theta / 2) * cornerRadius / Math.cos(theta / 2);
  1008.       cy = y + cornerRadius + Math.sin(angle + theta / 2) * cornerRadius / Math.cos(theta / 2);
  1009.       px = x + w - cornerRadius + Math.cos(angle + theta) * cornerRadius;
  1010.       py = y + cornerRadius + Math.sin(angle + theta) * cornerRadius;
  1011.       this.curveTo(cx,cy,px,py);
  1012.       angle += theta;
  1013.       cx = x + w - cornerRadius + Math.cos(angle + theta / 2) * cornerRadius / Math.cos(theta / 2);
  1014.       cy = y + cornerRadius + Math.sin(angle + theta / 2) * cornerRadius / Math.cos(theta / 2);
  1015.       px = x + w - cornerRadius + Math.cos(angle + theta) * cornerRadius;
  1016.       py = y + cornerRadius + Math.sin(angle + theta) * cornerRadius;
  1017.       this.curveTo(cx,cy,px,py);
  1018.       this.lineTo(x + w,y + h - cornerRadius);
  1019.       angle += theta;
  1020.       cx = x + w - cornerRadius + Math.cos(angle + theta / 2) * cornerRadius / Math.cos(theta / 2);
  1021.       cy = y + h - cornerRadius + Math.sin(angle + theta / 2) * cornerRadius / Math.cos(theta / 2);
  1022.       px = x + w - cornerRadius + Math.cos(angle + theta) * cornerRadius;
  1023.       py = y + h - cornerRadius + Math.sin(angle + theta) * cornerRadius;
  1024.       this.curveTo(cx,cy,px,py);
  1025.       angle += theta;
  1026.       cx = x + w - cornerRadius + Math.cos(angle + theta / 2) * cornerRadius / Math.cos(theta / 2);
  1027.       cy = y + h - cornerRadius + Math.sin(angle + theta / 2) * cornerRadius / Math.cos(theta / 2);
  1028.       px = x + w - cornerRadius + Math.cos(angle + theta) * cornerRadius;
  1029.       py = y + h - cornerRadius + Math.sin(angle + theta) * cornerRadius;
  1030.       this.curveTo(cx,cy,px,py);
  1031.       this.lineTo(x + cornerRadius,y + h);
  1032.       angle += theta;
  1033.       cx = x + cornerRadius + Math.cos(angle + theta / 2) * cornerRadius / Math.cos(theta / 2);
  1034.       cy = y + h - cornerRadius + Math.sin(angle + theta / 2) * cornerRadius / Math.cos(theta / 2);
  1035.       px = x + cornerRadius + Math.cos(angle + theta) * cornerRadius;
  1036.       py = y + h - cornerRadius + Math.sin(angle + theta) * cornerRadius;
  1037.       this.curveTo(cx,cy,px,py);
  1038.       angle += theta;
  1039.       cx = x + cornerRadius + Math.cos(angle + theta / 2) * cornerRadius / Math.cos(theta / 2);
  1040.       cy = y + h - cornerRadius + Math.sin(angle + theta / 2) * cornerRadius / Math.cos(theta / 2);
  1041.       px = x + cornerRadius + Math.cos(angle + theta) * cornerRadius;
  1042.       py = y + h - cornerRadius + Math.sin(angle + theta) * cornerRadius;
  1043.       this.curveTo(cx,cy,px,py);
  1044.       this.lineTo(x,y + cornerRadius);
  1045.       angle += theta;
  1046.       cx = x + cornerRadius + Math.cos(angle + theta / 2) * cornerRadius / Math.cos(theta / 2);
  1047.       cy = y + cornerRadius + Math.sin(angle + theta / 2) * cornerRadius / Math.cos(theta / 2);
  1048.       px = x + cornerRadius + Math.cos(angle + theta) * cornerRadius;
  1049.       py = y + cornerRadius + Math.sin(angle + theta) * cornerRadius;
  1050.       this.curveTo(cx,cy,px,py);
  1051.       angle += theta;
  1052.       cx = x + cornerRadius + Math.cos(angle + theta / 2) * cornerRadius / Math.cos(theta / 2);
  1053.       cy = y + cornerRadius + Math.sin(angle + theta / 2) * cornerRadius / Math.cos(theta / 2);
  1054.       px = x + cornerRadius + Math.cos(angle + theta) * cornerRadius;
  1055.       py = y + cornerRadius + Math.sin(angle + theta) * cornerRadius;
  1056.       this.curveTo(cx,cy,px,py);
  1057.    }
  1058.    else
  1059.    {
  1060.       this.moveTo(x,y);
  1061.       this.lineTo(x + w,y);
  1062.       this.lineTo(x + w,y + h);
  1063.       this.lineTo(x,y + h);
  1064.       this.lineTo(x,y);
  1065.    }
  1066. };
  1067. MovieClip.prototype.getCenterPoint = function()
  1068. {
  1069.    return {x:this._width / 2,y:this._height / 2};
  1070. };
  1071. MovieClip.prototype.drawDebugBorderD = function()
  1072. {
  1073.    this.lineStyle(1,0,25);
  1074.    var x;
  1075.    var y = 0;
  1076.    var w = this._width;
  1077.    var h = this._height;
  1078.    this.moveTo(x,y);
  1079.    this.lineTo(x + w,y);
  1080.    this.lineTo(x + w,y + h);
  1081.    this.lineTo(x,y + h);
  1082.    this.lineTo(x,y);
  1083. };
  1084. MovieClip.prototype.drawUnderline = function(len)
  1085. {
  1086.    len = len != null ? len : this._width;
  1087.    this.moveTo(0,this._height);
  1088.    this.lineTo(len,this._height);
  1089. };
  1090. if(PMSI.DepthManager == undefined)
  1091. {
  1092.    PMSI.DepthManager = {};
  1093.    PMSI.DepthManager._$depth = 0;
  1094.    PMSI.DepthManager.getNextDepth = function()
  1095.    {
  1096.       var next_depth = ++this._$depth;
  1097.       while(this._$depthsClaimed["dc" + next_depth])
  1098.       {
  1099.          next_depth = ++this._$depth;
  1100.       }
  1101.       return next_depth;
  1102.    };
  1103.    PMSI.DepthManager.reserveDepth = function(d)
  1104.    {
  1105.       if(this._$depthsClaimed == null)
  1106.       {
  1107.          this._$depthsClaimed = {};
  1108.       }
  1109.       if(d == null)
  1110.       {
  1111.          var d = ++this._$depth;
  1112.       }
  1113.       while(this._$depthsClaimed["dc" + d])
  1114.       {
  1115.          d++;
  1116.       }
  1117.       this._$depthsClaimed["dc" + d] = d;
  1118.       return d;
  1119.    };
  1120. }
  1121. ActivityInfoItem.prototype.toString = function()
  1122. {
  1123.    return this.text;
  1124. };
  1125. ActivityInfo.prototype.getIdString = function(separator)
  1126. {
  1127.    var sep = separator != null ? separator : ".";
  1128.    var idStr = "C" + this.activity.course + sep;
  1129.    idStr += "U" + this.activity.unit + sep;
  1130.    idStr += "S" + this.activity.section + sep;
  1131.    idStr += this.activity.topic + sep;
  1132.    if(this.activity.topicSet)
  1133.    {
  1134.       idStr += this.activity.topicSet + sep;
  1135.    }
  1136.    idStr += this.activity.difficultyLevel + this.activity.number.text;
  1137.    return idStr;
  1138. };
  1139. ActivityInfo.prototype.getId = ActivityInfo.prototype.getIdString;
  1140. ActivityInfo.prototype.getType = function()
  1141. {
  1142.    return this.activity.type;
  1143. };
  1144. ActivityInfo.prototype.hasAudio = function()
  1145. {
  1146.    return this.activity.audioFile == null ? false : true;
  1147. };
  1148. ActivityInfo.prototype.hasVideo = function()
  1149. {
  1150.    return this.activity.videoFile == null ? false : true;
  1151. };
  1152. ActivityInfo.prototype.hasPicture = function()
  1153. {
  1154.    return this.activity.artFile == null ? false : true;
  1155. };
  1156. ActivityInfo.prototype.setResolve = function()
  1157. {
  1158.    this.__resolve = ActivityInfo.prototype._myResolve;
  1159. };
  1160. ActivityInfo.prototype._myResolve = function(name)
  1161. {
  1162.    return this.activity[name];
  1163. };
  1164. ActivityInfo.prototype.getBytesLoaded = function()
  1165. {
  1166.    return this.xmlSource.getBytesLoaded();
  1167. };
  1168. ActivityInfo.prototype.getBytesTotal = function()
  1169. {
  1170.    return this.xmlSource.getBytesTotal();
  1171. };
  1172. ActivityInfo.prototype.load = function(url)
  1173. {
  1174.    this._reset();
  1175.    this.xmlSource = new XML();
  1176.    var x = this.xmlSource;
  1177.    x.parent = this;
  1178.    x.ignoreWhite = true;
  1179.    x.createAttributeArray = function(attrs)
  1180.    {
  1181.    };
  1182.    x.onLoad = function(success)
  1183.    {
  1184.       function helperR(node_xml, obj)
  1185.       {
  1186.          if(node_xml == null)
  1187.          {
  1188.             return undefined;
  1189.          }
  1190.          var nName = node_xml.nodeName;
  1191.          if(nName == "number")
  1192.          {
  1193.             nName = "activityNumber";
  1194.          }
  1195.          if(nName != null && obj[nName] == null)
  1196.          {
  1197.             var newObj = new ActivityInfoItem();
  1198.             newObj.text = node_xml.text.trim();
  1199.             if(node_xml.attributes)
  1200.             {
  1201.                trace("creating new attributes array");
  1202.                newObj.attributes = {};
  1203.                for(var oname in node_xml.attributes)
  1204.                {
  1205.                   newObj.attributes[oname] = node_xml.attributes[oname];
  1206.                }
  1207.             }
  1208.             obj[nName] = newObj;
  1209.          }
  1210.          else if(!(obj[nName] instanceof Array) && obj[nName] != null)
  1211.          {
  1212.             var temp = obj[nName];
  1213.             obj[nName] = [];
  1214.             obj[nName].push(temp);
  1215.          }
  1216.          var childObject = obj[nName];
  1217.          if(childObject instanceof Array)
  1218.          {
  1219.             var newObj = new ActivityInfoItem();
  1220.             newObj.text = node_xml.text.trim();
  1221.             if(node_xml.attributes)
  1222.             {
  1223.                trace("creating new attributes array");
  1224.                newObj.attributes = {};
  1225.                for(var oname in node_xml.attributes)
  1226.                {
  1227.                   newObj.attributes[oname] = node_xml.attributes[oname];
  1228.                }
  1229.             }
  1230.             childObject = newObj;
  1231.             obj[nName].push(childObject);
  1232.          }
  1233.          helperR(node_xml.firstChild,childObject);
  1234.          helperR(node_xml.nextSibling,obj);
  1235.       }
  1236.       if(success)
  1237.       {
  1238.          helperR(this.firstChild,this.parent);
  1239.          this.parent.setResolve();
  1240.       }
  1241.       this.parent.onLoad(success);
  1242.    };
  1243.    x.load(url);
  1244. };
  1245. ActivityInfo.prototype._reset = function()
  1246. {
  1247.    delete this.xmlSource;
  1248.    delete this.__resolve;
  1249.    delete this.activity;
  1250. };
  1251. TableClass = function(parent)
  1252. {
  1253.    this.parent = parent;
  1254.    this.reduceTextFields = true;
  1255.    this.rows = [];
  1256.    this.maxCellDims = {width:0,height:0};
  1257.    this.cellPadding = 4;
  1258.    this.cellSpacing = 4;
  1259.    this.colWidthMaxs = [];
  1260.    this.colPercentTable = [];
  1261.    this.borderSize = 1;
  1262.    this.width = 0;
  1263.    this.height = 0;
  1264.    this.oldWidth = this.width;
  1265.    this.oldHeight = this.oldHeight;
  1266.    this.originalWidth = 0;
  1267.    this.x = 0;
  1268.    this.y = 0;
  1269.    this.alteredColumns = {};
  1270.    var dep = PMSI.DepthManager.getNextDepth();
  1271.    this.borderClip = parent.createEmptyMovieClip("TableClassBorder" + dep,dep);
  1272. };
  1273. TableClass.prototype.setPosition = function(position)
  1274. {
  1275.    this.x = position.x;
  1276.    this.y = position.y;
  1277. };
  1278. TableClass.prototype.getPosition = function()
  1279. {
  1280.    return {x:this.x,y:this.y};
  1281. };
  1282. TableClass.prototype.setBorder = function(bsize)
  1283. {
  1284.    this.borderSize = bsize;
  1285. };
  1286. TableClass.prototype.addRow = function(newRow)
  1287. {
  1288.    this.rows.push(newRow);
  1289.    var cells = newRow.cells;
  1290.    var cellCount = cells.length;
  1291.    var cwms = this.colWidthMaxs;
  1292.    var cw = null;
  1293.    var newWidth = 0;
  1294.    var con = null;
  1295.    var c = 0;
  1296.    while(c < cellCount)
  1297.    {
  1298.       con = cells[c].getContent();
  1299.       cw = con == null ? cells[c].width : con._width;
  1300.       if(cwms[c] == null)
  1301.       {
  1302.          cwms[c] = cw;
  1303.       }
  1304.       else
  1305.       {
  1306.          cwms[c] = cw <= cwms[c] ? cwms[c] : cw;
  1307.       }
  1308.       newWidth += cwms[c];
  1309.       c++;
  1310.    }
  1311.    this.originalWidth = newWidth;
  1312.    this.width = newWidth;
  1313.    trace("NEW WIDTH: " + this.width);
  1314. };
  1315. TableClass.prototype.addRowSpacer = function(height, width, numCols)
  1316. {
  1317.    if(numCols == null && this.rows.length == 0)
  1318.    {
  1319.       return undefined;
  1320.    }
  1321.    numCols = this.rows[0].cells.length;
  1322.    var spacerRow = new TableRow();
  1323.    var spacerCell = null;
  1324.    var i = 0;
  1325.    while(i < numCols)
  1326.    {
  1327.       spacerCell = new TableCell();
  1328.       spacerCell.height = height;
  1329.       spacerCell.width = width;
  1330.       spacerRow.addCell(spacerCell);
  1331.       i++;
  1332.    }
  1333.    this.addRow(spacerRow);
  1334. };
  1335. TableClass.prototype.setCellPadding = function(cellPadding)
  1336. {
  1337.    this.cellPadding = cellPadding;
  1338.    this.redraw();
  1339. };
  1340. TableClass.prototype.setCellSpacing = function(cellSpacing)
  1341. {
  1342.    this.cellSpacing = cellSpacing;
  1343.    this.redraw();
  1344. };
  1345. TableClass.prototype.setWidth = function(width)
  1346. {
  1347.    this.oldWidth = this.width;
  1348.    this.width = width;
  1349.    this._recalcDimensions(width);
  1350.    this.redraw();
  1351.    this.redraw();
  1352. };
  1353. TableClass.prototype.setHeight = function(height)
  1354. {
  1355.    this.oldHeight = this.height;
  1356.    this.height = height;
  1357.    this.redraw();
  1358. };
  1359. TableClass.prototype.redraw = function()
  1360. {
  1361.    this.borderClip.clear();
  1362.    var rows = this.rows;
  1363.    var rc = rows.length;
  1364.    var tmdims = this.maxCellDims;
  1365.    var x;
  1366.    var y;
  1367.    var r;
  1368.    var cc;
  1369.    var con;
  1370.    var cols;
  1371.    var rmdims;
  1372.    var cell;
  1373.    var cmax;
  1374.    var offset;
  1375.    var voffset;
  1376.    var cwid;
  1377.    var wprec;
  1378.    var newwid;
  1379.    var lastColMax = null;
  1380.    var cpad = this.cellPadding;
  1381.    var cspace = this.cellSpacing;
  1382.    var r = 0;
  1383.    while(r < rc)
  1384.    {
  1385.       cols = rows[r].cells;
  1386.       cc = cols.length;
  1387.       rmdims = rows[r - 1].maxCellDims;
  1388.       if(r == 0)
  1389.       {
  1390.          y = this.y;
  1391.       }
  1392.       else
  1393.       {
  1394.          y += rmdims.height + this.cellSpacing;
  1395.       }
  1396.       var c = 0;
  1397.       while(c < cc)
  1398.       {
  1399.          cell = cols[c];
  1400.          con = cell.getContent();
  1401.          cwid = this.colWidthMaxs[c];
  1402.          this._resizeTextfield(con,cwid);
  1403.          if(cell.halign == "right")
  1404.          {
  1405.             offset = cwid - con._width;
  1406.          }
  1407.          else if(cell.halign == "center")
  1408.          {
  1409.             offset = (cwid - con._width) / 2;
  1410.          }
  1411.          else
  1412.          {
  1413.             offset = 0;
  1414.          }
  1415.          if(cell.valign == "bottom")
  1416.          {
  1417.             voffset = rows[r].maxCellDims.height - con._height;
  1418.          }
  1419.          else if(cell.valign == "center")
  1420.          {
  1421.             voffset = (rows[r].maxCellDims.height - con._height) / 2;
  1422.          }
  1423.          else
  1424.          {
  1425.             voffset = 0;
  1426.          }
  1427.          if(c == 0)
  1428.          {
  1429.             x = this.x;
  1430.             lastColMax = cwid;
  1431.          }
  1432.          else
  1433.          {
  1434.             cmax = lastColMax;
  1435.             x += cmax + this.cellSpacing;
  1436.          }
  1437.          con._x = x + offset;
  1438.          con._y = y + voffset;
  1439.          if(this.borderSize > 0)
  1440.          {
  1441.             this.borderClip.lineStyle(this.borderSize,10066329,100);
  1442.             this.borderClip.drawRect(x,y,cwid,rows[r].maxCellDims.height);
  1443.          }
  1444.          lastColMax = cwid;
  1445.          c++;
  1446.       }
  1447.       r++;
  1448.    }
  1449.    this._recalcHeights();
  1450. };
  1451. TableClass.prototype._resizeTextfield = function(oIns, w, h)
  1452. {
  1453.    var txt = oIns.content;
  1454.    if(txt._width > w)
  1455.    {
  1456.       txt.wordWrap = true;
  1457.       txt._width = w;
  1458.       txt._width = Math.round(txt._width);
  1459.       trace("text width: " + txt.textWidth);
  1460.       if(this.reduceTextFields)
  1461.       {
  1462.          var h = txt._height;
  1463.          var w = txt._width;
  1464.          var old_w = 0;
  1465.          var txtWidth = txt.textWidth;
  1466.          var i = w;
  1467.          while(h == txt._height)
  1468.          {
  1469.             if(i <= 0)
  1470.             {
  1471.                break;
  1472.             }
  1473.             if(txt.textWidth < txtWidth)
  1474.             {
  1475.                break;
  1476.             }
  1477.             txt._width--;
  1478.             i--;
  1479.          }
  1480.          txt._width = txt._width + 1;
  1481.       }
  1482.    }
  1483.    oIns._width = txt._width;
  1484. };
  1485. TableClass.prototype._recalcHeights = function()
  1486. {
  1487.    var rows = this.rows;
  1488.    var rc = rows.length;
  1489.    var cc;
  1490.    var cols;
  1491.    var cell;
  1492.    this.height = 0;
  1493.    var r = 0;
  1494.    while(r < rc)
  1495.    {
  1496.       cols = rows[r].cells;
  1497.       cc = cols.length;
  1498.       var c = 0;
  1499.       while(c < cc)
  1500.       {
  1501.          cell = cols[c];
  1502.          rows[r]._checkMaxCellDims(cell);
  1503.          this.height += rows[r].maxCellDims.height;
  1504.          c++;
  1505.       }
  1506.       r++;
  1507.    }
  1508. };
  1509. TableClass.prototype._findLargestColumn = function()
  1510. {
  1511.    var largestId;
  1512.    var largest;
  1513.    var cmaxs = this.colWidthMaxs;
  1514.    var i = 0;
  1515.    while(i < cmaxs.length)
  1516.    {
  1517.       trace("finding largest: " + cmaxs[i]);
  1518.       if(largest < cmaxs[i])
  1519.       {
  1520.          largest = cmaxs[i];
  1521.          largestId = i;
  1522.       }
  1523.       i++;
  1524.    }
  1525.    return largestId;
  1526. };
  1527. TableClass.prototype._recalcDimensions = function(newWidth)
  1528. {
  1529.    var cw = this._getTableWidth();
  1530.    if(newWidth > cw)
  1531.    {
  1532.       return undefined;
  1533.    }
  1534.    trace("\n\n----");
  1535.    trace("TableClass.prototype._recalcDimensions:");
  1536.    trace("current width: " + cw + ", new width: " + newWidth);
  1537.    delete this.alteredColumns;
  1538.    this.alteredColumns = {};
  1539.    this._resizeTableR(cw,newWidth);
  1540.    var addback = newWidth - this._getTableWidth();
  1541.    var cmaxs = this.colWidthMaxs;
  1542.    var prc;
  1543.    var cmax = 0;
  1544.    var acc = 0;
  1545.    for(var nm in this.alteredColumns)
  1546.    {
  1547.       trace("ALTERED COLUMNS: " + nm);
  1548.       if(!isNaN(nm))
  1549.       {
  1550.          acc++;
  1551.       }
  1552.    }
  1553.    for(var colid in this.alteredColumns)
  1554.    {
  1555.       trace("Addback: " + colid + ", " + addback / acc);
  1556.       this.colWidthMaxs[parseInt(colid)] = this.colWidthMaxs[parseInt(colid)] + addback / acc;
  1557.    }
  1558.    if(addback / acc > 0)
  1559.    {
  1560.    }
  1561.    this.width = newWidth;
  1562. };
  1563. TableClass.prototype._resizeTableR = function(lastWidth, targetWidth)
  1564. {
  1565.    if(lastWidth <= targetWidth)
  1566.    {
  1567.       return undefined;
  1568.    }
  1569.    var largest;
  1570.    var largestId = 0;
  1571.    var cmaxs = this.colWidthMaxs;
  1572.    var i = 0;
  1573.    while(i < cmaxs.length)
  1574.    {
  1575.       trace("finding largest: " + cmaxs[i]);
  1576.       if(largest < cmaxs[i])
  1577.       {
  1578.          largest = cmaxs[i];
  1579.          largestId = i;
  1580.       }
  1581.       i++;
  1582.    }
  1583.    var prc = largest / lastWidth;
  1584.    trace("prc: " + prc);
  1585.    var ncw = largest * prc;
  1586.    cmaxs[largestId] = ncw;
  1587.    this.alteredColumns[largestId] = largestId;
  1588.    trace("\n\nAFTER:");
  1589.    trace("new largest: " + ncw);
  1590.    trace("lastWidth: " + lastWidth);
  1591.    trace("largest: " + largest);
  1592.    trace("targetWidth: " + targetWidth);
  1593.    trace("nextWidth: " + (lastWidth - (largest - ncw)));
  1594.    if(prc == 1)
  1595.    {
  1596.       cmax[largestId] = targetWidth;
  1597.       return undefined;
  1598.    }
  1599.    this._resizeTableR(lastWidth - (largest - ncw),targetWidth);
  1600. };
  1601. TableClass.prototype._getTableWidth = function()
  1602. {
  1603.    var width = 0;
  1604.    var lasti = this.colWidthMaxs.length - 1;
  1605.    var i = 0;
  1606.    while(i < this.colWidthMaxs.length)
  1607.    {
  1608.       width += this.colWidthMaxs[i];
  1609.       i++;
  1610.    }
  1611.    return width;
  1612. };
  1613. TableClass.prototype.init = function()
  1614. {
  1615.    this.redraw();
  1616. };
  1617. TableRow = function()
  1618. {
  1619.    this.cells = [];
  1620.    this.maxCellDims = {width:0,height:0};
  1621. };
  1622. TableRow.prototype.addCell = function(cell)
  1623. {
  1624.    this.cells.push(cell);
  1625.    var cc = cell.getContent();
  1626.    var cw = cc == null ? cell.width : cc._width;
  1627.    var ch = cc == null ? cell.height : cc._height;
  1628.    var mw = this.maxCellDims.width;
  1629.    var mh = this.maxCellDims.height;
  1630.    this.maxCellDims.width = cw <= mw ? mw : cw;
  1631.    this.maxCellDims.height = ch <= mh ? mh : ch;
  1632. };
  1633. TableRow.prototype._checkMaxCellDims = function(cell)
  1634. {
  1635.    var cc = cell.getContent();
  1636.    var cw = cc == null ? cell.width : cc._width;
  1637.    var ch = cc == null ? cell.height : cc._height;
  1638.    var mw = this.maxCellDims.width;
  1639.    var mh = this.maxCellDims.height;
  1640.    this.maxCellDims.width = cw <= mw ? mw : cw;
  1641.    this.maxCellDims.height = ch <= mh ? mh : ch;
  1642. };
  1643. TableCell = function(content)
  1644. {
  1645.    this.content = content;
  1646. };
  1647. TableCell.prototype.setContent = function(content)
  1648. {
  1649.    this.content = content;
  1650. };
  1651. TableCell.prototype.getContent = function()
  1652. {
  1653.    return this.content;
  1654. };
  1655. TableCell.prototype.setWidth = function(width, isPercent)
  1656. {
  1657.    this.widthIsPercent = isPercent != null ? true : false;
  1658.    this.width = width;
  1659. };
  1660. TableCell.prototype.setHeight = function(height, isPercent)
  1661. {
  1662.    this.heightIsPercent = isPercent != null ? true : false;
  1663.    this.height = height;
  1664. };
  1665. TableCell.prototype.setHAlign = function(halign)
  1666. {
  1667.    this.halign = halign;
  1668. };
  1669. TableCell.prototype.setVAlign = function(valign)
  1670. {
  1671.    this.valign = valign;
  1672. };
  1673. mediaFrame._visible = false;
  1674. stop();
  1675. var TXT_DEBUG_SHOW_BORDERS = false;
  1676. var testFile1 = "activities/data/c3.u5.s1.gr.a2.xml";
  1677. if(_parent)
  1678. {
  1679.    master = _parent;
  1680. }
  1681. else
  1682. {
  1683.    master = this;
  1684. }
  1685. if(master.layoutInfo == null)
  1686. {
  1687.    var layoutInfo = {};
  1688.    layoutInfo.titleTextColor = 3636920;
  1689.    layoutInfo.answerRollOverColor = 16695085;
  1690.    layoutInfo.answerRollOutColor = 3636920;
  1691.    layoutInfo.answerSelectColor = 2309272;
  1692.    layoutInfo.questionTextColor = 2309272;
  1693.    layoutInfo.instTextColor = 2309272;
  1694.    layoutInfo.doAnswerFill = false;
  1695.    layoutInfo.rightSideBuffer = 60;
  1696.    layoutInfo.box = {};
  1697.    layoutInfo.box.x = 260;
  1698.    layoutInfo.box.y = 94;
  1699.    layoutInfo.box.views = [];
  1700.    layoutInfo.box.widthWithBox = 300;
  1701.    layoutInfo.box.heightWithBox = 300;
  1702.    layoutInfo.box.widthWithoutBox = 300;
  1703.    layoutInfo.box.heightWithoutBox = 300;
  1704.    layoutinfo.MAX_WIDTH = 520;
  1705.    layoutInfo.MAX_HEIGHT = 380;
  1706.    layoutInfo.questionIndent = 30;
  1707.    layoutInfo.selectionRadius = 6;
  1708.    layoutInfo.drawSelectionCircle = true;
  1709.    layoutInfo.lineSpacing = 5;
  1710.    layoutInfo.selectionBorderThickness = 1;
  1711.    layoutInfo.instTextFormat = new TextFormat();
  1712.    layoutInfo.instTextFormat.font = "Formata_Normal";
  1713.    layoutInfo.instTextFormat.size = 12;
  1714.    layoutInfo.instTextFormat.color = layoutInfo.instTextColor;
  1715.    layoutInfo.qTextFormat = new TextFormat();
  1716.    layoutInfo.qTextFormat.font = "Formata_Normal";
  1717.    layoutInfo.qTextFormat.size = 12;
  1718.    layoutInfo.qTextFormat.color = layoutInfo.questionTextColor;
  1719.    layoutInfo.qTextFormat.align = "right";
  1720.    layoutInfo.answerTextFormat1 = new TextFormat();
  1721.    layoutInfo.answerTextFormat1.font = "Formata_Normal";
  1722.    layoutInfo.answerTextFormat1.size = 12;
  1723.    layoutInfo.answerTextFormat1.color = layoutInfo.answerRollOutColor;
  1724.    layoutInfo.answerTextFormat2 = new TextFormat();
  1725.    layoutInfo.answerTextFormat2.font = "Formata_Normal";
  1726.    layoutInfo.answerTextFormat2.size = 12;
  1727.    layoutInfo.answerTextFormat2.color = layoutInfo.answerRollOutColor;
  1728.    layoutInfo.titleTextFormat = new TextFormat();
  1729.    layoutInfo.titleTextFormat.font = "TriplexCondSerifBlack";
  1730.    layoutInfo.titleTextFormat.size = 24;
  1731.    layoutInfo.titleTextFormat.color = layoutInfo.titleTextColor;
  1732. }
  1733. else
  1734. {
  1735.    layoutInfo = master.layoutInfo;
  1736. }
  1737. layoutInfo.temp4InstWidth = 250;
  1738. layoutInfo.temp4InstY = 0;
  1739. var ai = new ActivityInfo();
  1740. ai._parent = this;
  1741. ai.onLoad = function(success)
  1742. {
  1743.    trace("id:   " + this.getIdString());
  1744.    trace("type: " + this.type);
  1745.    var i = 0;
  1746.    while(i < this.questions.question.length)
  1747.    {
  1748.       trace(i + 1 + ". " + this.questions.question[i].questionText);
  1749.       i++;
  1750.    }
  1751.    this._parent.render();
  1752.    trace("Time: " + (getTimer() - t) / 1000);
  1753. };
  1754. if(_parent == null)
  1755. {
  1756.    loadActivity(testFile1);
  1757. }
  1758. answer.onRelease = function()
  1759. {
  1760.    checkAnswers();
  1761. };
  1762. answer.onRollOver = function()
  1763. {
  1764.    this.gotoAndStop("rollOver");
  1765. };
  1766. answer.onRollOut = function()
  1767. {
  1768.    this.gotoAndStop("rollOut");
  1769. };
  1770. TAGS = {};
  1771. TAGS.BLANK_OPEN = "[:blank:]";
  1772. TAGS.BLANK_CLOSE = "[:/blank:]";
  1773.